<template>
	<view class="diy-coupon"
		:style="{ padding: itemData.style.paddingTop + 'px 20rpx' }">
		<scroll-view scroll-x="true">
			<view class="swiper ">
				<view class="coupon-item" v-for="(item, index) in listData"
					:key="index">
					<view class="money">
						<template v-if="item.coupon_type.value == 10">
							<text class="money_icon">￥</text>
							<text class="f40">{{ item.reduce_price*1 }}</text>
						</template>
						<template v-if="item.coupon_type.value == 20">
							<text class="f40">{{ item.discount*1 }}</text>
							<text class="f24">折</text>
						</template>
					</view>
					<view class="full_money">
						<text class="f24">{{item.min_price>0?'满'+item.min_price*1+'元可用':'无门槛'}}</text>
					</view>
					
					<view class="coupon_type">
						<text v-if="item.apply_range==10">全品类券</text>
						<text v-if="item.apply_range==20">指定商品可用</text>
						<text v-if="item.apply_range==30">指定品类可用</text>
					</view>
					
					<view v-if="item.state.value == 1" class="right-receive" @click="receiveCoupon(index)">
						<view class="lr-tb">立即领取</view>
					</view>
					<view v-else class="right-receive">
						<view class="lr-tb">{{ item.state.text }}</view>
					</view>
				</view>
			</view>
		</scroll-view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				/*是否显示点*/
				indicatorDots: false,
				/*是否自动*/
				autoplay: true,
				/*切换时间*/
				interval: 5000,
				/*动画过渡时间*/
				duration: 1000,
				/*数据列表*/
				listData: []
			};
		},
		props: ['itemData'],
		created() {
			this.listData = this.itemData.data;
		},
		methods: {
			scroll(e) {},
			/**
			 * 领取优惠券
			 */
			receiveCoupon: function(index) {
				let self = this;
				let item = self.listData[index];
				if (item.state.value == 0) {
					return false;
				}
				self._post(
					'user.coupon/receive', {
						coupon_id: item.coupon_id
					},
					function(result) {
						uni.showToast({
							title: '领取成功',
							icon: 'success',
							mask: true,
							duration: 2000
						});
						item.state.value = 0;
						item.state.text = '已领取';
					}
				);
			}
		}
	};
</script>

<style lang="scss">
	.right-receive{
		margin-top: 28rpx;
		.lr-tb{
			width: 150rpx;
			margin: 0 auto;
			height: 56rpx;
			line-height: 56rpx;
			border-radius: 28rpx;
			text-align: center;
			background-color:#ED4549 ;
			color: #fff;
		}
	}
	.coupon_type{
		color: #777777;
		text-align: center;
		font-size: 24rpx;
		margin-top: 8rpx;
	}
	.full_money{
		color: #ED4549;
		text-align: center;
		margin-top: 8rpx;
	}
	.money{
		color: #ED4549;
		font-weight: bold;
		text-align: center;
		margin-top: 10rpx;
		.money_icon{
			font-size: 28rpx;
		}
	}
	.diy-coupon {
		margin: 20rpx;
		border-radius: 16rpx;
		background: linear-gradient(#FF633D,#FF8D21);
	}

	.f-s-0 {
		flex-shrink: 0;
	}

	.diy-coupon .swiper {
		display: flex;
		justify-content: flex-start;
		overflow-x: auto;
	}

	.diy-coupon .coupon-item {
		width: 202rpx;
		height: 234rpx;
		margin: 8rpx;
		border-radius: 8rpx;
		overflow: hidden;
		background: url('@/static/coupon.png') no-repeat;
		background-size: 100% 100%;
		
	}
	
	
</style>
